package com.pkx.guide.fcms.service.impl;

import com.pkx.guide.common.util.StringUtils;
import com.pkx.guide.fcms.service.FcmsPlayItemService;
import com.pkx.guide.info.entity.TInfoGuidePlayItem;
import com.sansi.playlist.PlayItem;
import com.sansi.playlist.entry.BaseColour;
import com.sansi.playlist.entry.PlayTimeBase;
import com.sansi.playlist.entry.TextBase;
import org.springframework.stereotype.Service;

import java.util.UUID;

@Service("text")
public class FcmsTextPlayItemServiceImpl implements FcmsPlayItemService {

    /**
     * 生成播放项
     * @return
     */
    @Override
    public PlayItem generatePlayItem(TInfoGuidePlayItem tInfoGuidePlayItem, String playListName, int index){
        String[] backColourArr = new String[5];
        if (StringUtils.isEmpty(tInfoGuidePlayItem.getFontColour())){
            backColourArr = new String[]{"128", "0", "0", "0", "0"};
        } else {
            backColourArr = tInfoGuidePlayItem.getFontColour().split(",");
        }
        BaseColour fontColour = new BaseColour(Integer.parseInt(backColourArr[0]),Integer.parseInt(backColourArr[1]),Integer.parseInt(backColourArr[2]),Integer.parseInt(backColourArr[3]),Integer.parseInt(backColourArr[4]));
        TextBase textBase = new TextBase(tInfoGuidePlayItem.getTextType(),tInfoGuidePlayItem.getText());
        // 字体大小，如果显示屏支持矢量字库，则字体大小可以自由设置
        // 如果显示屏只支持点阵字库，则字体大小取值有效范围：(16,16)、(24,24)、(32,32)；(48,48)或(64,64) )二者选一 ；(96,96) 超大屏可能支持
        // 备注：字号是否支持可以进行赋值尝试，然后观察显示屏是否显示，如果不显示则表示该值不支持。
        textBase.setFontSize(tInfoGuidePlayItem.getFontSize());
        // fontName 字体名称，目前只支持：h（黑体）、k（楷体）、s（宋体）、f（仿宋体）等四种字体，其它值均为非法值
        textBase.setFontName(tInfoGuidePlayItem.getFontName());
        textBase.setFontColour(fontColour);
        PlayTimeBase textPlayTime = new PlayTimeBase(tInfoGuidePlayItem.getPlayTotalTime());
        String id = UUID.randomUUID().toString().replace("-", "");
        String itemName = "ITEM" + playListName + "0" + index;
        PlayItem textPlayItem = new PlayItem(index, id, itemName, textBase, textPlayTime);
        textPlayItem.setX(tInfoGuidePlayItem.getPlayItemX());
        textPlayItem.setY(tInfoGuidePlayItem.getPlayItemY());
        tInfoGuidePlayItem.setPlayItemNo(index);
        tInfoGuidePlayItem.setPlayItemId(id);
        tInfoGuidePlayItem.setPlayItemName(itemName);
        return textPlayItem;
    }
}
